package com.lemon.smartsafety.ui.fragment.safe.data;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.AppService;
import com.lemon.smartsafety.app.BundleKey;
import com.lemon.smartsafety.entity.common.PanelRcvBaseDataI;
import com.lemon.smartsafety.entity.common.PanelRcvBaseListItem;
import com.lemon.smartsafety.entity.event.common.PanelEvent;
import com.lemon.smartsafety.entity.safe.company.CompanyInfo;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.ui.adapter.common.PanelRcvBaseAdapter;
import com.lemon.smartsafety.ui.adapter.common.RcvViewType;
import com.lemon.smartsafety.ui.adapter.safe.data.ItemTag;
import com.lemon.smartsafetynew.ui.fragment.base.BaseLocalListFragment;
import com.lemon.smartsafety.utils.app.UserTypeHelper;
import com.lemon.smartsafety.utils.common.LoggerHelper;
import com.lemon.smartsafety.utils.common.StringUtils;

import kale.adapter.LemonRcvAdapter;

/**
 * Created by Cooliean on 16/3/24.
 * 数据采集 主功能面板
 */
public class SafeDataCollectionPanelFragment extends BaseLocalListFragment<PanelRcvBaseDataI> implements RecyclerTClickListener<PanelRcvBaseDataI<ItemTag>> {

    private CompanyInfo mCompanyInfo = null;


    private LoggerHelper loggerHelper = new LoggerHelper(SafeDataCollectionPanelFragment.class);

    public static SafeDataCollectionPanelFragment newInstance() {
        return new SafeDataCollectionPanelFragment();
    }

    private void initData() {
        PanelRcvBaseListItem dataHead1 = new PanelRcvBaseListItem();
        dataHead1.setPanelViewType(RcvViewType.PanelViewType.TYPE_SECTION_HEAD);
        mDataList.add(dataHead1);


        PanelRcvBaseListItem dataTitle = new PanelRcvBaseListItem();
        dataTitle.setPanelViewType(RcvViewType.PanelViewType.TYPE_TITLE);
        if (mCompanyInfo != null) {
            dataTitle.setTitle(StringUtils.nullValue(mCompanyInfo.getCompany_name()));
        }
        mDataList.add(dataTitle);


        PanelRcvBaseListItem dataHead2 = new PanelRcvBaseListItem();
        dataHead2.setPanelViewType(RcvViewType.PanelViewType.TYPE_SECTION_HEAD);
        mDataList.add(dataHead2);

        //用户类型
        PanelRcvBaseListItem itemCheck = new PanelRcvBaseListItem();
        itemCheck.setPanelViewType(RcvViewType.PanelViewType.TYPE_COMMON_ITEM);
        itemCheck.setTitle(getString(R.string.role_title));
        itemCheck.setValue(UserTypeHelper.getUserTypeName());
        itemCheck.setShowArrow(false);
        itemCheck.setDisable(true);
        itemCheck.setIcon(R.drawable.ic_item_role);
        mDataList.add(itemCheck);


        PanelRcvBaseListItem dataHead21 = new PanelRcvBaseListItem();
        dataHead21.setPanelViewType(RcvViewType.PanelViewType.TYPE_SECTION_HEAD);
        mDataList.add(dataHead21);


        //数据采集标题
        PanelRcvBaseListItem<ItemTag> dataHead3 = new PanelRcvBaseListItem<ItemTag>();
        dataHead3.setPanelViewType(RcvViewType.PanelViewType.TYPE_SECTION_HEAD);
        dataHead3.setTitle(getString(R.string.safe_data_title));
        mDataList.add(dataHead3);


        //单位基本信息
        PanelRcvBaseListItem<ItemTag> itemBasicInfo = new PanelRcvBaseListItem<ItemTag>();
        itemBasicInfo.setTag(ItemTag.TAG_BASIC_ITEM);
        itemBasicInfo.setPanelViewType(RcvViewType.PanelViewType.TYPE_COMMON_ITEM);
        itemBasicInfo.setTitle(getString(R.string.safe_data_basic_info_record));
        itemBasicInfo.setShowArrow(true);
        itemBasicInfo.setIcon(R.drawable.ic_data_record);
        mDataList.add(itemBasicInfo);


        //建筑场所登记
        PanelRcvBaseListItem<ItemTag> itemBuildingInfo = new PanelRcvBaseListItem<ItemTag>();
        itemBuildingInfo.setTag(ItemTag.TAG_BUILDING_RECORD);
        itemBuildingInfo.setPanelViewType(RcvViewType.PanelViewType.TYPE_COMMON_ITEM);
        itemBuildingInfo.setTitle(getString(R.string.safe_data_build_record));
        itemBuildingInfo.setShowArrow(true);
        itemBuildingInfo.setIcon(R.drawable.ic_build_record);
        mDataList.add(itemBuildingInfo);


        //检查项目管理
        PanelRcvBaseListItem<ItemTag> itemCheckManager = new PanelRcvBaseListItem<ItemTag>();
        itemCheckManager.setTag(ItemTag.TAG_CHECK_ITEM_MANAGER);
        itemCheckManager.setPanelViewType(RcvViewType.PanelViewType.TYPE_COMMON_ITEM);
        itemCheckManager.setTitle(getString(R.string.safe_data_check_item_manager));
        itemCheckManager.setShowArrow(true);
        itemCheckManager.setIcon(R.drawable.ic_check_item_manager);
        mDataList.add(itemCheckManager);


        //维保单位登记
        PanelRcvBaseListItem<ItemTag> itemKeepContact = new PanelRcvBaseListItem<ItemTag>();
        itemKeepContact.setTag(ItemTag.TAG_WEI_BAO_RECORD);
        itemKeepContact.setPanelViewType(RcvViewType.PanelViewType.TYPE_COMMON_ITEM);
        itemKeepContact.setTitle(getString(R.string.safe_data_keep_contact_record));
        itemKeepContact.setShowArrow(true);
        itemKeepContact.setIcon(R.drawable.ic_wei_bao_record);
        mDataList.add(itemKeepContact);


        //物业单位登记
        PanelRcvBaseListItem<ItemTag> itemWuYe = new PanelRcvBaseListItem<ItemTag>();
        itemWuYe.setTag(ItemTag.TAG_WU_YE_RECORD);
        itemWuYe.setPanelViewType(RcvViewType.PanelViewType.TYPE_COMMON_ITEM);
        itemWuYe.setTitle(getString(R.string.safe_data_wuye_record));
        itemWuYe.setShowArrow(true);
        itemWuYe.setIcon(R.drawable.ic_wuye_manager);
        mDataList.add(itemWuYe);


        //安全管理设置
        PanelRcvBaseListItem<ItemTag> itemSafeManager = new PanelRcvBaseListItem<ItemTag>();
        itemSafeManager.setTag(ItemTag.TAG_SAFE_MANAGER_SETTING);
        itemSafeManager.setPanelViewType(RcvViewType.PanelViewType.TYPE_COMMON_ITEM);
        itemSafeManager.setTitle(getString(R.string.safe_data_safe_manager_setting));
        itemSafeManager.setShowArrow(true);
        itemSafeManager.setIcon(R.drawable.ic_item_setting);
        mDataList.add(itemSafeManager);

    }

    @Override
    protected void initViews() {
        if (getArguments() != null) {
            mCompanyInfo = (CompanyInfo) getArguments().getSerializable(BundleKey.COMPANY_INFO);
        }
        super.initViews();
    }

    @Override
    public boolean goRefreshOnCreate() {
        return false;
    }

    @Override
    public LemonRcvAdapter<PanelRcvBaseDataI> getLemonAdapter() {
        initData();
        return new PanelRcvBaseAdapter(mDataList, this);
    }


    @Override
    public void onPullRefresh() {

    }


    @Override
    public void onItemClick(PanelRcvBaseDataI<ItemTag> data, int position) {
        PanelEvent<ItemTag> event = new PanelEvent<ItemTag>();
        event.setTag(SafeDataCollectionPanelFragment.class.getName());
        event.setDataI(data);
        AppService.getBus().post(event);
    }
}
